﻿using UnityEngine;
using ZCUIManager;

namespace ZCMain
{
    public class MainPaintView : UIBaseView
    {
        [SerializeField] private float m_ShowLiveTime = 1.0f;
        [SerializeField] private float m_ShowLiveSpeed = 15.0f;
        private float m_ShowLiveStartTime;
        private bool m_ShowLiveTimeEnable;
        private Vector2 m_TargetSize;
        private Vector2 m_DiffSize;

        public override bool isUIView => false;

        public override void Initialize(eUIType uiType, GameObject go)
        {
            base.Initialize(uiType, go);
            Hide();
        }

        public override void Tick()
        {
            base.Tick();
            if (m_ShowLiveTimeEnable)
            {
                if (Time.time - m_ShowLiveStartTime >= m_ShowLiveTime)
                {
                    if (!MainController.Instance.Editing)
                    {
                        Hide();
                    }
                    m_RectTransform.sizeDelta = m_TargetSize;
                    m_ShowLiveTimeEnable = false;
                }
                else
                {
                    m_RectTransform.sizeDelta = Vector2.Lerp(m_RectTransform.sizeDelta, m_TargetSize, Time.deltaTime * m_ShowLiveSpeed);
                }
            }
        }

        public void ShowLiveTime(float value)
        {
            m_TargetSize = Vector2.one * value;
            m_ShowLiveStartTime = Time.time;
            m_ShowLiveTimeEnable = true;
            Show();
        }

        public void SetPoint(Vector2 point)
        {
            RectTransformUtility.ScreenPointToLocalPointInRectangle(ProgramManager.mainCanvasRectTransform, point, Camera.main, out Vector2 position);
            m_RectTransform.anchoredPosition = position;
        }
    }
}
